<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <button @click="state.count++">{{state.count}}</button>
        <button @click="changeCount">{{state.count}}</button>
        <!-- <div>{{ num }} --- {{ str }} --- {{ b }}</div>
        <button @click="num++">{{ num }}</button> -->
        <button @click="state.data[0].age++">{{state.data[0].age}}</button>
    </div>


    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
    <script>
        const { createApp, ref, reactive } = Vue;
        createApp({
            setup() {
                // 使用reactive方法创建响应式对象 状态
                // reactive对象不能包装基本数据类型：number,string,boolean,null,undefined,Symbol
                const state = reactive({
                    count: ref(10), // 这里可以自动解包
                    data: [
                        { name: '张三', age: 20 },
                        { name: '李四', age: 19 },
                    ]
                })
                console.log("state=>", state);
                // 下面的三行代码是错误的
                // const num = reactive(10)
                // const str = reactive("hello")
                // const b = reactive(true)

                // 在js中访问reactive对象,直接访问
                const changeCount = () => {
                    state.count++
                }



                return {
                    state,
                    changeCount,


                }

            }
        }).mount("#app")
    </script>
</body>

</html>